﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the G.O.S.E(Game Online Server Engine) for .NET.
//
//                 2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Demo_G.O.S.E.ServerEngine.Map;
using Demo_G.O.S.E.ServerEngine.Util;
using Demo_G.O.S.E.ServerEngine.World;
using Demo_G.O.S.E.ServerEngine.Common;
using Demo_G.O.S.E.ServerEngine.Network;
using Demo_G.O.S.E.ServerEngine.Creature;
#endregion

namespace Demo_G.O.S.E.ServerEngine.Item
{
    // 道具的信息
    //////////////////////////////////////////////////////////////////////////
    // 道具(单一)
    // 道具(容器)
    // 
    // 
    // 

    // 道具的行为
    //////////////////////////////////////////////////////////////////////////
    // 道具(交易-玩家)
    // 道具(装备-玩家)
    // 道具(容器-道具)
    // 道具(位置-地图)
    // 道具(存在/消失-地图)
    // 道具(其它)
    // 
    // 

    /// <summary>
    /// 
    /// </summary>
    public class BaseItem : IEntity, IComparable, IComparable<BaseItem>
    {
        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        public BaseItem()
        {
            DefaultItemInit();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serial"></param>
        public BaseItem( Serial serial )
        {
            m_Serial = serial;
            DefaultItemInit();
        }

        #region zh-CHS 道具的初始化 | en
        /// <summary>
        /// 缺省的初始化人物
        /// </summary>
        protected virtual void DefaultItemInit()
        {
        }
        #endregion

        #endregion

        #region zh-CHS 共有属性 | en Public Properties

        #region zh-CHS Serial属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Serial m_Serial = new Serial();
        #endregion
        /// <summary>
        /// 道具的唯一序列号GUID
        /// </summary>
        public Serial Serial
        {
            get { return m_Serial; }
            set
            {
                Serial oldValueSerial = m_Serial;

                EventHandler<BeforeUpdateSerialEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateSerial;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateSerialEventArgs eventArgs = new BeforeUpdateSerialEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Serial = value;
                m_BaseItemState.UpdateSerial();

                EventHandler<AfterUpdateSerialEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateSerial;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateSerialEventArgs eventArgs = new AfterUpdateSerialEventArgs( oldValueSerial, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS X属性 | en Public Properties

        /// <summary>
        /// 道具的X坐标点
        /// </summary>
        public float X
        {
            get { return m_Location.X; }
            set
            {
                float oldX = m_Location.X;

                EventHandler<BeforeUpdateXEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateX;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateXEventArgs eventArgs = new BeforeUpdateXEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Location.X = value;
                m_BaseItemState.UpdateX();

                EventHandler<AfterUpdateXEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateX;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateXEventArgs eventArgs = new AfterUpdateXEventArgs( oldX, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS Y属性 | en Public Properties

        /// <summary>
        /// 道具的Y坐标点
        /// </summary>
        public float Y
        {
            get { return m_Location.Y; }
            set
            {
                float oldY = m_Location.Y;

                EventHandler<BeforeUpdateYEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateY;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateYEventArgs eventArgs = new BeforeUpdateYEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Location.Y = value;
                m_BaseItemState.UpdateY();

                EventHandler<AfterUpdateYEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateY;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateYEventArgs eventArgs = new AfterUpdateYEventArgs( oldY, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS Z属性 | en Public Properties

        /// <summary>
        /// 道具的Z坐标点
        /// </summary>
        public float Z
        {
            get { return m_Location.Z; }
            set
            {
                float oldZ = m_Location.Z;

                EventHandler<BeforeUpdateZEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateZ;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateZEventArgs eventArgs = new BeforeUpdateZEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Location.Z = value;
                m_BaseItemState.UpdateZ();

                EventHandler<AfterUpdateZEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateZ;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateZEventArgs eventArgs = new AfterUpdateZEventArgs( oldZ, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS Orientation属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private float m_Orientation = 0;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public float Orientation
        {
            get { return m_Orientation; }
            set
            {
                float oldOrientation = m_Orientation;

                EventHandler<BeforeUpdateOrientationEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateOrientation;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateOrientationEventArgs eventArgs = new BeforeUpdateOrientationEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Orientation = value;
                m_BaseItemState.UpdateOrientation();

                EventHandler<AfterUpdateOrientationEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateOrientation;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateOrientationEventArgs eventArgs = new AfterUpdateOrientationEventArgs( oldOrientation, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS Location属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Point3D m_Location = new Point3D();
        #endregion
        /// <summary>
        /// 道具在地图上面的坐标点
        /// </summary>
        public Point3D Location
        {
            get { return m_Location; }
            set
            {
                Point3D oldLocation = m_Location;

                EventHandler<BeforeUpdateLocationEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateLocation;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateLocationEventArgs eventArgs = new BeforeUpdateLocationEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Location = value;
                m_BaseItemState.UpdateLocation();

                EventHandler<AfterUpdateLocationEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateLocation;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateLocationEventArgs eventArgs = new AfterUpdateLocationEventArgs( oldLocation, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS Map属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private BaseMap m_BaseMap = null;
        #endregion
        /// <summary>
        /// 地图的位置
        /// </summary>
        public BaseMap Map
        {
            get { return m_BaseMap; }
            set
            {
                BaseMap oldBaseMap = m_BaseMap;

                EventHandler<BeforeUpdateMapEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateMap;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateMapEventArgs eventArgs = new BeforeUpdateMapEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_BaseMap = value;
                m_BaseItemState.UpdateMap();

                EventHandler<AfterUpdateMapEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateMap;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateMapEventArgs eventArgs = new AfterUpdateMapEventArgs( oldBaseMap, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #region zh-CHS 地图点激活方法 | en Protected Internal Methods
        /// <summary>
        /// 地图点激活
        /// </summary>
        protected internal virtual void OnSectorActivate()
        {
        }

        /// <summary>
        /// 地图点不激活
        /// </summary>
        protected internal virtual void OnSectorDeactivate()
        {
        }
        #endregion

        #endregion

        #region zh-CHS Name属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private string m_Name = string.Empty;
        #endregion
        /// <summary>
        /// 道具的名字
        /// </summary>
        public string Name
        {
            get { return m_Name; }
            set
            {
                string oldName = m_Name;

                EventHandler<BeforeUpdateNameEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateName;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateNameEventArgs eventArgs = new BeforeUpdateNameEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Name = value;
                m_BaseItemState.UpdateName();

                EventHandler<AfterUpdateNameEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateName;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateNameEventArgs eventArgs = new AfterUpdateNameEventArgs( oldName, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS Owner属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private BaseCreature m_Owner = null;
        #endregion
        /// <summary>
        /// 拥有者的对象
        /// </summary>
        public virtual BaseCreature Owner
        {
            get { return m_Owner; }
            set
            {
                BaseCreature oldOwner = m_Owner;

                EventHandler<BeforeUpdateOwnerEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateOwner;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateOwnerEventArgs eventArgs = new BeforeUpdateOwnerEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Owner = value;
                m_BaseItemState.UpdateOwner();

                EventHandler<AfterUpdateOwnerEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateOwner;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateOwnerEventArgs eventArgs = new AfterUpdateOwnerEventArgs( oldOwner, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #endregion

        #region zh-CHS Parent属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private BaseItem m_Parent = null;
        #endregion
        /// <summary>
        /// 拥有者的对象
        /// </summary>
        public virtual BaseItem Parent
        {
            get { return m_Parent; }
            set
            {
                BaseItem oldParent = m_Parent;

                EventHandler<BeforeUpdateParentEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateParent;
                if ( tempBeforeEventArgs != null )
                {
                    BeforeUpdateParentEventArgs eventArgs = new BeforeUpdateParentEventArgs( value, this );
                    tempBeforeEventArgs( this, eventArgs );

                    if ( eventArgs.IsCancel == true )
                        return;
                }

                m_Parent = value;
                m_BaseItemState.UpdatemParent();

                EventHandler<AfterUpdateParentEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateParent;
                if ( tempAfterEventArgs != null )
                {
                    AfterUpdateParentEventArgs eventArgs = new AfterUpdateParentEventArgs( oldParent, this );
                    tempAfterEventArgs( this, eventArgs );
                }
            }
        }

        #region zh-CHS 共有方法 | en Public Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parentItem"></param>
        protected virtual void OnParentDeleted( BaseItem parentItem )
        {
        }
        #endregion

        #endregion

        #region zh-CHS 子道具列表 属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 人物的道具列表
        /// </summary>
        private SafeDictionary<long, BaseItem> m_ChildItems = new SafeDictionary<long, BaseItem>();
        #endregion
        /// <summary>
        /// 人物的道具列表(包裹与身上)
        /// </summary>
        /// <returns></returns>
        [MultiThreadedWarningAttribute( "(子道具)当前的数组是列表临时产生的,不能保存数组用于以后操作:警告!" )]
        public BaseItem[] ChildItemsToArray()
        {
            return m_ChildItems.ToArray();
        }

        #region zh-CHS 共有方法 | en Public Methods

        /// <summary>
        /// 添加道具
        /// </summary>
        /// <param name="item"></param>
        public bool AddChildItem( long iItemSerial, BaseItem baseItem )
        {
            if ( baseItem == null )
            {
                Debug.WriteLine( "BaseCreature.AddItem(...) - baseItem == null error!" );

                return false;
            }

            if ( m_Deleted == true )
                return false;

            EventHandler<BeforeAddChildItemCallEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeAddChildItemCall;
            if ( tempBeforeEventArgs != null )
            {
                BeforeAddChildItemCallEventArgs eventArgs = new BeforeAddChildItemCallEventArgs( baseItem, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            m_ChildItems.Add( iItemSerial, baseItem );

            m_BaseItemState.UpdateAddChildItemCall();

            EventHandler<AfterAddChildItemCallEventArgs> tempAfterEventArgs = m_ThreadEventAfterAddChildItemCall;
            if ( tempAfterEventArgs != null )
            {
                AfterAddChildItemCallEventArgs eventArgs = new AfterAddChildItemCallEventArgs( baseItem, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 移出道具
        /// </summary>
        /// <param name="item"></param>
        public bool RemoveChildItem( long iItemSerial )
        {
            if ( m_Deleted == true )
                return false;

            BaseItem baseItem = FindChildItemOnSerial( iItemSerial );
            if ( baseItem == null )
                return false;

            EventHandler<BeforeRemoveChildItemCallEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeRemoveChildItemCall;
            if ( tempBeforeEventArgs != null )
            {
                BeforeRemoveChildItemCallEventArgs eventArgs = new BeforeRemoveChildItemCallEventArgs( baseItem, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            m_ChildItems.Remove( iItemSerial );

            m_BaseItemState.UpdateRemoveChildItemCall();

            EventHandler<AfterRemoveChildItemCallEventArgs> tempAfterEventArgs = m_ThreadEventAfterRemoveChildItemCall;
            if ( tempAfterEventArgs != null )
            {
                AfterRemoveChildItemCallEventArgs eventArgs = new AfterRemoveChildItemCallEventArgs( baseItem, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 在身上找道具
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public BaseItem FindChildItemOnSerial( long iItemSerial )
        {
            return m_ChildItems.GetValue( iItemSerial );
        }

        #endregion

        #endregion

        #region zh-CHS BaseItemState属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 道具的的状态
        /// </summary>
        private BaseItemState m_BaseItemState = new BaseItemState();
        #endregion
        /// <summary>
        /// 道具的的状态
        /// </summary>
        public BaseItemState BaseItemState
        {
            get { return m_BaseItemState; }
        }

        #endregion

        #region zh-CHS Deleted属性 | en Public Properties

        #region zh-CHS 私有静态成员变量 | en Private Static Member Variables
        /// <summary>
        /// 
        /// </summary>
        private bool m_Deleted = false;
        #endregion
        /// <summary>
        /// 当前的道具是否已经删除
        /// </summary>
        public bool Deleted
        {
            get { return m_Deleted; }
        }

        #region zh-CHS 共有方法 | en Public Methods
        /// <summary>
        /// 删除道具
        /// </summary>
        public void Delete()
        {
            EventHandler<BaseItemEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeDeleteCall;
            if ( tempBeforeEventArgs != null )
            {
                BaseItemEventArgs eventArgs = new BaseItemEventArgs( this );
                tempBeforeEventArgs( this, eventArgs );
            }

            BaseItem[] l_BaseItemArray = ChildItemsToArray();
            if ( l_BaseItemArray != null )
            {
                foreach ( BaseItem baseItem in l_BaseItemArray )
                    baseItem.OnParentDeleted( this );
            }

            m_Deleted = true;

            EventHandler<BaseItemEventArgs> tempAfterEventArgs = m_ThreadEventAfterDeleteCall;
            if ( tempAfterEventArgs != null )
            {
                BaseItemEventArgs eventArgs = new BaseItemEventArgs( this );
                tempAfterEventArgs( this, eventArgs );
            }
        }
        #endregion

        #endregion

        #region zh-CHS BaseWorld属性 | en BaseWorld Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 管理当前的世界服务
        /// </summary>
        private BaseWorld m_BaseWorld = null;
        #endregion
        /// <summary>
        /// 管理当前的世界服务
        /// </summary>
        public BaseWorld BaseWorld
        {
            get { return m_BaseWorld; }
        }

        #region zh-CHS 内部方法 | en Internal Methods
        /// <summary>
        /// 设置管理当前的世界服务
        /// </summary>
        /// <param name="baseWorld"></param>
        internal void SetBaseWorld( BaseWorld baseWorld )
        {
            m_BaseWorld = baseWorld;
        }
        #endregion

        #endregion

        #region zh-CHS Saving属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private bool m_Saving = false;
        #endregion
        /// <summary>
        /// 是否正在存储数据中
        /// </summary>
        public bool Saving
        {
            get { return m_Saving; }
        }

        #region zh-CHS 共有方法 | en Public Methods
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockSave = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 保存人物的数据
        /// </summary>
        public void Save()
        {
            // 移动物体的数据必须要成功才返回
            ReaderWriterLockSlimEx.EnterWriteLock( m_LockSave );
            {
                // 保存数据中......
                m_Saving = true;

                EventHandler<BaseItemEventArgs> tempEventArgs = m_ThreadEventItemSave;
                // 保存数据
                if ( tempEventArgs != null )
                {
                    LOGs.WriteLine( LogMessageType.MSG_NOTICE, "道具: 开始保存道具({0})数据中......", m_Name );

                    BaseItemEventArgs eventArgs = new BaseItemEventArgs( this );
                    tempEventArgs( this, eventArgs );

                    LOGs.WriteLine( LogMessageType.MSG_NOTICE, "道具: 道具({0})数据保存完毕.", m_Name );
                }

                // 保存数据结束......
                m_Saving = false;
            }
            ReaderWriterLockSlimEx.ExitWriteLock( m_LockSave );
        }
        #endregion

        #endregion

        #region zh-CHS SlotId属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Serial m_SlotId = Serial.MinusOne;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public long SlotId
        {
            get { return m_SlotId; }
        }

        #region zh-CHS 内部方法 | en Internal Methods
        /// <summary>
        /// 设置管理当前的世界服务
        /// </summary>
        /// <param name="baseWorld"></param>
        internal void SetSlotId( long iSlotId )
        {
            m_SlotId = iSlotId;
        }
        #endregion

        #endregion

        #endregion

        #region zh-CHS 内部属性 | en Internal Properties
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Sector m_Sector = null;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        internal Sector Sector
        {
            get { return m_Sector; }
            set { m_Sector = value; }
        }
        #endregion

        #region zh-CHS 共有方法 | en Public Methods

        #region zh-CHS 给出人物范围内的道具或人物或对象 | en
        /// <summary>
        /// 给出人物范围内的道具
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public IPooledEnumerable GetItemsInRange( int iRange )
        {
            BaseMap tempBaseMap = m_BaseMap;
            if ( tempBaseMap == null )
            {
                Debug.WriteLine( "BaseItem.GetItemsInRange(...) - m_BaseMap == null error!" );

                return NullEnumerable.Instance;
            }

            return m_BaseMap.GetItemsInRange( m_Location, iRange );
        }

        /// <summary>
        /// 给出人物范围内的对象
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public IPooledEnumerable GetObjectsInRange( int iRange )
        {
            BaseMap tempBaseMap = m_BaseMap;
            if ( tempBaseMap == null )
            {
                Debug.WriteLine( "BaseItem.GetItemsInRange(...) - m_BaseMap == null error!" );

                return NullEnumerable.Instance;
            }

            return m_BaseMap.GetObjectsInRange( m_Location, iRange );
        }

        /// <summary>
        /// 给出人物范围内的人物
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public IPooledEnumerable GetMobilesInRange( int iRange )
        {
            BaseMap tempBaseMap = m_BaseMap;
            if ( tempBaseMap == null )
            {
                Debug.WriteLine( "BaseItem.GetItemsInRange(...) - m_BaseMap == null error!" );

                return NullEnumerable.Instance;
            }

            return m_BaseMap.GetCreaturesInRange( m_Location, iRange );
        }

        /// <summary>
        /// 给出人物范围内的客户端
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public IPooledEnumerable GetClientsInRange( int iRange )
        {
            BaseMap tempBaseMap = m_BaseMap;
            if ( tempBaseMap == null )
            {
                Debug.WriteLine( "BaseItem.GetItemsInRange(...) - m_BaseMap == null error!" );

                return NullEnumerable.Instance;
            }

            return m_BaseMap.GetClientsInRange( m_Location, iRange );
        }
        #endregion

        #region zh-CHS 创建一个新的自身道具 | en Method
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private ConstructorInfo m_ConstructorInfo = null;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public BaseItem CreateNewInstance()
        {
            if ( m_ConstructorInfo != null )
            {
                object returnObject = m_ConstructorInfo.Invoke( null );

                BaseItem baseItem = returnObject as BaseItem;
                if ( baseItem == null )
                {
                    Debug.WriteLine( "BaseItem.CreateNewInstance(...) - baseItem == null error!" );
                    return null;
                }

                return baseItem;
            }

            Type type = GetType();
            ConstructorInfo[] constructorInfoArray = type.GetConstructors();

            foreach ( ConstructorInfo constructorInfo in constructorInfoArray )
            {
                ParameterInfo[] parameterInfoArray = constructorInfo.GetParameters();
                if ( parameterInfoArray.Length == 0 )
                {
                    m_ConstructorInfo = constructorInfo;

                    object returnObject = m_ConstructorInfo.Invoke( null );

                    BaseItem baseItem = returnObject as BaseItem;
                    if ( baseItem == null )
                    {
                        Debug.WriteLine( "BaseItem.CreateNewInstance(...) - baseItem == null error!" );
                        return null;
                    }

                    return baseItem;
                }
            }

            return null;
        }
        #endregion

        #region zh-CHS 道具的主处理行为 | en
        #region zh-CHS 私有静态成员变量 | en Private Static Member Variables
        /// <summary>
        /// 
        /// </summary>
        private static Queue<BaseItem> s_SliceQueue = new Queue<BaseItem>();
        /// <summary>
        /// 
        /// </summary>
        private static ReaderWriterLockSlim s_LockSliceQueue = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="flag"></param>
        internal static void Slice()
        {
            // 使用数组减少锁定时间
            BaseItem[] baseCreatureArray = null;

            if ( ReaderWriterLockSlimEx.TryEnterWriteLock( s_LockSliceQueue ) == false ) return;
            {
                if ( s_SliceQueue.Count > 0 )
                {
                    baseCreatureArray = s_SliceQueue.ToArray();
                    s_SliceQueue.Clear();
                }
            }
            ReaderWriterLockSlimEx.ExitWriteLock( s_LockSliceQueue );

            // 如果没有需要处理的数据则返回
            if ( baseCreatureArray == null )
                return;

            foreach ( BaseItem baseCreature in baseCreatureArray )
            {
                baseCreature.ProcessSlice();
                baseCreature.BaseItemState.RestoreAll();

                baseCreature.OutSliceQueue();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected virtual void ProcessSlice()
        {
            EventHandler<BaseItemEventArgs> tempEventArgs = m_ThreadEventSlice;
            if ( tempEventArgs != null )
            {
                BaseItemEventArgs eventArgs = new BaseItemEventArgs( this );
                tempEventArgs( this, eventArgs );
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void UpdateSlice()
        {
            if ( m_BaseMap == null || m_Deleted == true )
                return;

            if ( InSliceQueue() == false )
                return;

            ReaderWriterLockSlimEx.EnterWriteLock( s_LockSliceQueue );
            {
                s_SliceQueue.Enqueue( this );
            }
            ReaderWriterLockSlimEx.ExitWriteLock( s_LockSliceQueue );

            BaseWorld tempBaseWorld = m_BaseWorld;
            if ( tempBaseWorld != null )
                tempBaseWorld.SetWorldSignal();
            else
                Debug.WriteLine( "BaseCreature.Slice(...) - m_BaseWorld == null error!" );
        }
        #endregion

        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation
        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo( IEntity other )
        {
            if ( other == null )
                return 1;

            return m_Serial.CompareTo( other.Serial );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo( BaseItem other )
        {
            return CompareTo( other as IEntity );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo( object xObject )
        {
            return CompareTo( xObject as IEntity );
        }
        #endregion

        #region zh-CHS 方法覆盖 | en Override Methods
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return m_Name;
        }
        #endregion

        #region zh-CHS 共有事件 | en Public Event
        #region zh-CHS Slice事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BaseItemEventArgs> m_ThreadEventSlice;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventSlice = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BaseItemEventArgs> ThreadSlice
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventSlice );
                {
                    m_ThreadEventSlice += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventSlice );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventSlice );
                {
                    m_ThreadEventSlice -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventSlice );
            }
        }
        #endregion

        #region zh-CHS ItemSave事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BaseItemEventArgs> m_ThreadEventItemSave;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventItemSave = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BaseItemEventArgs> ThreadItemSave
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventItemSave );
                {
                    m_ThreadEventItemSave += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventItemSave );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventItemSave );
                {
                    m_ThreadEventItemSave -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventItemSave );
            }
        }
        #endregion

        #region zh-CHS Serial事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateSerialEventArgs> m_ThreadEventBeforeUpdateSerial;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateSerial = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateSerialEventArgs> ThreadBeforeUpdateSerial
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateSerial );
                {
                    m_ThreadEventBeforeUpdateSerial += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateSerial );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateSerial );
                {
                    m_ThreadEventBeforeUpdateSerial -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateSerial );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateSerialEventArgs> m_ThreadEventAfterUpdateSerial;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateSerial = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateSerialEventArgs> ThreadAfterUpdateSerial
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateSerial );
                {
                    m_ThreadEventAfterUpdateSerial += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateSerial );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateSerial );
                {
                    m_ThreadEventAfterUpdateSerial -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateSerial );
            }
        }
        #endregion

        #region zh-CHS X事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateXEventArgs> m_ThreadEventBeforeUpdateX;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateX = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateXEventArgs> ThreadBeforeUpdateX
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateX );
                {
                    m_ThreadEventBeforeUpdateX += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateX );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateX );
                {
                    m_ThreadEventBeforeUpdateX -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateX );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateXEventArgs> m_ThreadEventAfterUpdateX;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateX = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateXEventArgs> ThreadAfterUpdateX
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateX );
                {
                    m_ThreadEventAfterUpdateX += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateX );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateX );
                {
                    m_ThreadEventAfterUpdateX -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateX );
            }
        }
        #endregion

        #region zh-CHS Y事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateYEventArgs> m_ThreadEventBeforeUpdateY;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateY = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateYEventArgs> ThreadBeforeUpdateY
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateY );
                {
                    m_ThreadEventBeforeUpdateY += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateY );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateY );
                {
                    m_ThreadEventBeforeUpdateY -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateY );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateYEventArgs> m_ThreadEventAfterUpdateY;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateY = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateYEventArgs> ThreadAfterUpdateY
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateY );
                {
                    m_ThreadEventAfterUpdateY += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateY );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateY );
                {
                    m_ThreadEventAfterUpdateY -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateY );
            }
        }
        #endregion

        #region zh-CHS Z事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateZEventArgs> m_ThreadEventBeforeUpdateZ;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateZ = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateZEventArgs> ThreadBeforeUpdateZ
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateZ );
                {
                    m_ThreadEventBeforeUpdateZ += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateZ );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateZ );
                {
                    m_ThreadEventBeforeUpdateZ -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateZ );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateZEventArgs> m_ThreadEventAfterUpdateZ;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateZ = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateZEventArgs> ThreadAfterUpdateZ
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateZ );
                {
                    m_ThreadEventAfterUpdateZ += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateZ );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateZ );
                {
                    m_ThreadEventAfterUpdateZ -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateZ );
            }
        }
        #endregion

        #region zh-CHS Orientation事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateOrientationEventArgs> m_ThreadEventBeforeUpdateOrientation;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateOrientation = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateOrientationEventArgs> ThreadBeforeUpdateOrientation
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateOrientation );
                {
                    m_ThreadEventBeforeUpdateOrientation += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateOrientation );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateOrientation );
                {
                    m_ThreadEventBeforeUpdateOrientation -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateOrientation );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateOrientationEventArgs> m_ThreadEventAfterUpdateOrientation;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateOrientation = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateOrientationEventArgs> ThreadAfterUpdateOrientation
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateOrientation );
                {
                    m_ThreadEventAfterUpdateOrientation += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateOrientation );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateOrientation );
                {
                    m_ThreadEventAfterUpdateOrientation -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateOrientation );
            }
        }
        #endregion

        #region zh-CHS Location事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateLocationEventArgs> m_ThreadEventBeforeUpdateLocation;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateLocation = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateLocationEventArgs> ThreadBeforeUpdateLocation
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateLocation );
                {
                    m_ThreadEventBeforeUpdateLocation += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateLocation );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateLocation );
                {
                    m_ThreadEventBeforeUpdateLocation -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateLocation );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateLocationEventArgs> m_ThreadEventAfterUpdateLocation;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateLocation = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateLocationEventArgs> ThreadAfterUpdateLocation
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateLocation );
                {
                    m_ThreadEventAfterUpdateLocation += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateLocation );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateLocation );
                {
                    m_ThreadEventAfterUpdateLocation -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateLocation );
            }
        }
        #endregion

        #region zh-CHS Map事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateMapEventArgs> m_ThreadEventBeforeUpdateMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateMapEventArgs> ThreadBeforeUpdateMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateMap );
                {
                    m_ThreadEventBeforeUpdateMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateMap );
                {
                    m_ThreadEventBeforeUpdateMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateMap );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateMapEventArgs> m_ThreadEventAfterUpdateMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateMapEventArgs> ThreadAfterUpdateMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateMap );
                {
                    m_ThreadEventAfterUpdateMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateMap );
                {
                    m_ThreadEventAfterUpdateMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateMap );
            }
        }
        #endregion

        #region zh-CHS Name事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateNameEventArgs> m_ThreadEventBeforeUpdateName;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateName = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateNameEventArgs> ThreadBeforeUpdateName
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateName );
                {
                    m_ThreadEventBeforeUpdateName += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateName );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateName );
                {
                    m_ThreadEventBeforeUpdateName -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateName );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateNameEventArgs> m_ThreadEventAfterUpdateName;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateName = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateNameEventArgs> ThreadAfterUpdateName
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateName );
                {
                    m_ThreadEventAfterUpdateName += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateName );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateName );
                {
                    m_ThreadEventAfterUpdateName -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateName );
            }
        }
        #endregion

        #region zh-CHS ItemTemplate事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateItemTemplateEventArgs> m_ThreadEventBeforeUpdateItemTemplate;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateItemTemplate = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateItemTemplateEventArgs> ThreadBeforeUpdateItemTemplate
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateItemTemplate );
                {
                    m_ThreadEventBeforeUpdateItemTemplate += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateItemTemplate );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateItemTemplate );
                {
                    m_ThreadEventBeforeUpdateItemTemplate -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateItemTemplate );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateItemTemplateEventArgs> m_ThreadEventAfterUpdateItemTemplate;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateItemTemplate = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateItemTemplateEventArgs> ThreadAfterUpdateItemTemplate
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateItemTemplate );
                {
                    m_ThreadEventAfterUpdateItemTemplate += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateItemTemplate );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateItemTemplate );
                {
                    m_ThreadEventAfterUpdateItemTemplate -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateItemTemplate );
            }
        }
        #endregion

        #region zh-CHS Owner事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateOwnerEventArgs> m_ThreadEventBeforeUpdateOwner;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateOwner = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateOwnerEventArgs> ThreadBeforeUpdateOwner
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateOwner );
                {
                    m_ThreadEventBeforeUpdateOwner += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateOwner );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateOwner );
                {
                    m_ThreadEventBeforeUpdateOwner -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateOwner );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateOwnerEventArgs> m_ThreadEventAfterUpdateOwner;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateOwner = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateOwnerEventArgs> ThreadAfterUpdateOwner
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateOwner );
                {
                    m_ThreadEventAfterUpdateOwner += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateOwner );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateOwner );
                {
                    m_ThreadEventAfterUpdateOwner -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateOwner );
            }
        }
        #endregion

        #region zh-CHS Parent事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeUpdateParentEventArgs> m_ThreadEventBeforeUpdateParent;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeUpdateParent = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeUpdateParentEventArgs> ThreadBeforeUpdateParent
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateParent );
                {
                    m_ThreadEventBeforeUpdateParent += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateParent );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeUpdateParent );
                {
                    m_ThreadEventBeforeUpdateParent -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeUpdateParent );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterUpdateParentEventArgs> m_ThreadEventAfterUpdateParent;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterUpdateParent = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterUpdateParentEventArgs> ThreadAfterUpdateParent
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateParent );
                {
                    m_ThreadEventAfterUpdateParent += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateParent );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterUpdateParent );
                {
                    m_ThreadEventAfterUpdateParent -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterUpdateParent );
            }
        }
        #endregion

        #region zh-CHS AddChildItemCall事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeAddChildItemCallEventArgs> m_ThreadEventBeforeAddChildItemCall;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeAddChildItemCall = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeAddChildItemCallEventArgs> ThreadBeforeAddChildItemCall
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeAddChildItemCall );
                {
                    m_ThreadEventBeforeAddChildItemCall += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeAddChildItemCall );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeAddChildItemCall );
                {
                    m_ThreadEventBeforeAddChildItemCall -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeAddChildItemCall );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterAddChildItemCallEventArgs> m_ThreadEventAfterAddChildItemCall;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterAddChildItemCall = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterAddChildItemCallEventArgs> ThreadAfterAddChildItemCall
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterAddChildItemCall );
                {
                    m_ThreadEventAfterAddChildItemCall += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterAddChildItemCall );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterAddChildItemCall );
                {
                    m_ThreadEventAfterAddChildItemCall -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterAddChildItemCall );
            }
        }
        #endregion

        #region zh-CHS RemoveChildItemCall事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeRemoveChildItemCallEventArgs> m_ThreadEventBeforeRemoveChildItemCall;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeRemoveChildItemCall = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeRemoveChildItemCallEventArgs> ThreadBeforeRemoveChildItemCall
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeRemoveChildItemCall );
                {
                    m_ThreadEventBeforeRemoveChildItemCall += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeRemoveChildItemCall );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeRemoveChildItemCall );
                {
                    m_ThreadEventBeforeRemoveChildItemCall -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeRemoveChildItemCall );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterRemoveChildItemCallEventArgs> m_ThreadEventAfterRemoveChildItemCall;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterRemoveChildItemCall = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterRemoveChildItemCallEventArgs> ThreadAfterRemoveChildItemCall
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterRemoveChildItemCall );
                {
                    m_ThreadEventAfterRemoveChildItemCall += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterRemoveChildItemCall );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterRemoveChildItemCall );
                {
                    m_ThreadEventAfterRemoveChildItemCall -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterRemoveChildItemCall );
            }
        }
        #endregion

        #region zh-CHS DeleteCall事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BaseItemEventArgs> m_ThreadEventBeforeDeleteCall;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventBeforeDeleteCall = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BaseItemEventArgs> ThreadBeforeDeleteCall
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeDeleteCall );
                {
                    m_ThreadEventBeforeDeleteCall += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeDeleteCall );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventBeforeDeleteCall );
                {
                    m_ThreadEventBeforeDeleteCall -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventBeforeDeleteCall );
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BaseItemEventArgs> m_ThreadEventAfterDeleteCall;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockThreadEventAfterDeleteCall = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BaseItemEventArgs> ThreadAfterDeleteCall
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterDeleteCall );
                {
                    m_ThreadEventAfterDeleteCall += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterDeleteCall );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadEventAfterDeleteCall );
                {
                    m_ThreadEventAfterDeleteCall -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadEventAfterDeleteCall );
            }
        }
        #endregion

        #endregion

        #region zh-CHS 内部 Slice Queue 方法 | en Internal Slice Queue Methods
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private bool m_bIsInSliceQueue = false;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockIsInSliceQueue = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        internal bool InSliceQueue()
        {
            bool bReturn = false;

            if ( ReaderWriterLockSlimEx.TryEnterWriteLock( m_LockIsInSliceQueue ) == false )
                return false;
            else
            {
                if ( m_bIsInSliceQueue == false ) // 没有锁定
                    bReturn = m_bIsInSliceQueue = true;
            }
            ReaderWriterLockSlimEx.ExitWriteLock( m_LockIsInSliceQueue );

            return bReturn;
        }

        /// <summary>
        /// 
        /// </summary>
        internal void OutSliceQueue()
        {
            ReaderWriterLockSlimEx.EnterWriteLock( m_LockIsInSliceQueue );
            {
                m_bIsInSliceQueue = false;
            }
            ReaderWriterLockSlimEx.ExitWriteLock( m_LockIsInSliceQueue );
        }
        #endregion
    }
}
#endregion